package jwdt.web.action;

import jwdt.xadmin.info.bean.TNews;
import jwdt.xadmin.info.bean.TType;

import com.ezerg.db.Jdb;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;

public class DetailAction extends BaseAction {
	public Page execute(Form f, Module m) throws Exception {
		//
		int id = f.getInt("id");
		TNews news = (TNews)Jdb.get().get(TNews.class, id);
		if(news == null) {
			f.add("ret", "您要查看的信息不存在");
			return m.findPage("tips");
		}
		//
		int typeid = news.getTypeid();
		TType type = (TType) Jdb.get().get(TType.class, typeid);
		if(type==null) {
			f.add("ret", "您选择的栏目不存在");
			return m.findPage("tips");
		}
		f.add("type", type);
		//全站最新
		f.add("qzzx", Jdb.get().query(super.select_news+" where checked=1 "+super.order_news+" limit 8"));
		//相关阅读
		f.add("about", Jdb.get().query(super.select_news+" where checked=1 and typeid in(select id from t_type where fid= " + typeid + ") or typeid= "+ typeid + super.order_news+" limit 8"));
		int rows = 7;
		super.getListByTypeid(typeid, "objs", rows, f);//
		super.getListByTypeid2(typeid, 0, "objs0", rows, f);//
		super.getListByTypeid2(typeid, 1, "objs1", rows, f);//
		super.getListByTypeid2(typeid, 2, "objs2", rows, f);//
		super.getListByTypeid2(typeid, 3, "objs3", rows, f);//
		super.getListByTypeid2(typeid, 4, "objs4", rows, f);//
		//
		try {
			Jdb.get().execute("update t_news set click=click+1 where id="+id,false);
		} catch(Exception e){}
		news.setClick(news.getClick().intValue()+1);
		f.add("obj", news);
		//广告图片
		f.add("advimg3", Jdb.get().queryDataMap("select id,title,path,url from t_images where position=3 and zt=1 limit 1"));
		f.add("advimg4", Jdb.get().queryDataMap("select id,title,path,url from t_images where position=4 and zt=1 limit 1"));
		f.add("advimg5", Jdb.get().queryDataMap("select id,title,path,url from t_images where position=5 and zt=1 limit 1"));
		f.add("advimg6", Jdb.get().queryDataMap("select id,title,path,url from t_images where position=5 and zt=1 limit 1"));
		return m.findPage("detail");
	}
}
